package textrandom;

import java.util.Random;
import java.util.Scanner;

public class randomNum {
    public static void main(String[] args) {
        guessNumber();
    }

    public static void guessNumber() {
        Random r = new Random();
        Scanner sc = new Scanner(System.in);
        int randomNum = r.nextInt(100)+1;

        while (true)
        {
            System.out.println("请输入猜测的数字（范围1-100）：");
            int num = sc.nextInt();
            if (num>randomNum)
            {
                System.out.println("猜大了。");
            }
            else if (num< randomNum)
            {
                System.out.println("猜小了。");

            }
            else
            {
                System.out.println("猜对了");
                break;
            }
        }
        System.out.println("恭喜！");
    }


}
